package client.comm.commlib.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import client.comm.commlib.R;


/**
 */
public class ToastUtil {
    private static Toast mToast;
    private static TextView tv_content;
    private static View toastRoot;

    public synchronized static void show(String msg, Context context) {
//        if (mToast == null || toastRoot == null || tv_content == null) {
            mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
            toastRoot = LayoutInflater.from(context).inflate(R.layout.common_toast_item, null);
            tv_content = (TextView) toastRoot.findViewById(R.id.tv_content);
            tv_content.setText(msg);
            mToast.setView(toastRoot);
//        } else {
////            mToast.setText(msg);
//            tv_content.setText(msg);
//            mToast.setDuration(Toast.LENGTH_SHORT);
//        }
        mToast.show();
    }

    public static void cancelToast() {
        if (mToast != null) {
            mToast.cancel();
        }
    }
}
